//初始化
var form;
var $;
var element;
layui.use(['element','form'],function(){
    form = layui.form;
    $ = layui.jquery;
    element = layui.element;
    setVideoData();
    setProductData();
    setOtherData();
    setNums();
    load();
    getEchartsUserInfo();
    window.setInterval(getEchartsUserInfo,300000);
    window.setInterval(setVideoData,300000);
    window.setInterval(setProductData,300000);
    window.setInterval(setOtherData,300000);
    window.setInterval(setNums,300000);
});
function load(){
    $(".tit_btn").bind('click',function(){
        location.reload();
    })
    $(".tit_btn2").bind('click',function(){
        window.history.go(-1);  //返回上一页
    })
}
function setNums(){
    $.get("/personnel/selFeedBackNums",function (res) {
        $(".videoNums").html(res.obj.dataA);
        $(".productNums").html(res.obj.dataB);
        $(".otherNums").html(res.obj.dataC);
    });
}
function setVideoData(){
    var feedbackType = 2;
    $.post("/personnel/selFeedDatas",{feedbackType:feedbackType},function (res) {
        $(".videoA").html(res.obj.dataA);
        $(".videoB").html(res.obj.dataB);
        $(".videoC").html(res.obj.dataC);
        $(".videoD").html(res.obj.dataD);
    });
}
function setProductData(){
    var feedbackType = 3;
    $.post("/personnel/selFeedDatas",{feedbackType:feedbackType},function (res) {
        $(".productA").html(res.obj.dataA);
        $(".productB").html(res.obj.dataB);
        $(".productC").html(res.obj.dataC);
        $(".productD").html(res.obj.dataD);
    });
}
function setOtherData(){
    var feedbackType = 4;
    $.post("/personnel/selFeedDatas",{feedbackType:feedbackType},function (res) {
        $(".otherA").html(res.obj.dataA);
        $(".otherB").html(res.obj.dataB);
        $(".otherC").html(res.obj.dataC);
        $(".otherD").html(res.obj.dataD);
    });
}
function getEchartsUserInfo(){
    var feedbackType = 2;
    $.post("/personnel/selFeedEcharts",{feedbackType:feedbackType}, function (res) {
        var feedback = 3;
        $.post("/personnel/selFeedEcharts",{feedbackType:feedback}, function (data) {
            var feed = 4;
            $.post("/personnel/selFeedEcharts",{feedbackType:feed}, function (item) {
                getEcharts(res.obj,data.obj,item.obj);
            });
        });
    });
}
function getEcharts(res,data,item){
    var chartDom = document.getElementById('userecharts');
    var myChart = echarts.init(chartDom);
    var option;

    option = {
        title: {
            text: '用户反馈统计列图标',
            subtext: '思云产品'
        },
        tooltip: {
            trigger: 'axis'
        },
        legend: {
            data: ['视频反馈', '商品反馈','其他反馈']
        },
        toolbox: {
            show: true,
            feature: {
                dataView: {show: true, readOnly: false},
                magicType: {show: true, type: ['line', 'bar']},
                restore: {show: true},
                saveAsImage: {show: true}
            }
        },
        calculable: true,
        xAxis: [
            {
                type: 'category',
                data: ['很好', '好', '一般', '差']
            }
        ],
        yAxis: [
            {
                type: 'value'
            }
        ],
        series: [
            {
                name: '视频反馈',
                type: 'bar',
                data: res,
                markPoint: {
                    data: [
                        {type: 'max', name: '最大值'},
                        {type: 'min', name: '最小值'}
                    ]
                },
                markLine: {
                    data: [
                        {type: 'average', name: '平均值'}
                    ]
                }
            },
            {
                name: '商品反馈',
                type: 'bar',
                data: data,
                markPoint: {
                    data: [
                        {type: 'max', name: '最大值'},
                        {type: 'min', name: '最小值'}
                    ]
                },
                markLine: {
                    data: [
                        {type: 'average', name: '平均值'}
                    ]
                }
            },
            {
                name: '其他反馈',
                type: 'bar',
                data: item,
                markPoint: {
                    data: [
                        {type: 'max', name: '最大值'},
                        {type: 'min', name: '最小值'}
                    ]
                },
                markLine: {
                    data: [
                        {type: 'average', name: '平均值'}
                    ]
                }
            }
        ]
    };
    option && myChart.setOption(option);
    window.onresize = myChart.resize;
}